package com.bnlr.lrparking.adapter;

import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.bnlr.lrparking.R;
import com.bnlr.lrparking.model.ByStagesM;
import com.bnlr.lrparking.model.StagesBankBean;

import java.util.List;

/**
 * 分期期限列表
 *
 * @author tian
 * @date 2017/9/16
 */

public class ByStagesAdapter extends BaseQuickAdapter<StagesBankBean.DataBean.DrStagesBean, BaseViewHolder> {

    private int defaultSelection = -1;
    private boolean isFirst = true;

    public ByStagesAdapter(@Nullable List<StagesBankBean.DataBean.DrStagesBean> data) {
        super(R.layout.item_bystages, data);
    }

    @Override
    protected void convert(BaseViewHolder holder, StagesBankBean.DataBean.DrStagesBean item) {
        holder.setIsRecyclable(false);
        holder.setText(R.id.tv_bystages_num, item.getNumBers() + "");

        if (holder.getAdapterPosition() == defaultSelection) {
            holder.setBackgroundRes(R.id.rely_bystages, R.mipmap.pay_moneybg_click);
            holder.setTextColor(R.id.tv_bystages_num, mContext.getResources().getColor(R.color.write));
            holder.setTextColor(R.id.tv_bystages_fen, mContext.getResources().getColor(R.color.write));
            holder.setTextColor(R.id.tv_bystages_qi, mContext.getResources().getColor(R.color.write));
        } else {// 未选中时设置selector0
            holder.setBackgroundRes(R.id.rely_bystages, R.mipmap.pay_moneybg_nor);
            holder.setTextColor(R.id.tv_bystages_num, mContext.getResources().getColor(R.color.text_color));
            holder.setTextColor(R.id.tv_bystages_fen, mContext.getResources().getColor(R.color.text_color));
            holder.setTextColor(R.id.tv_bystages_qi, mContext.getResources().getColor(R.color.text_color));
        }
        if (item.getIsDefault() == 1) {
            if (isFirst) {
                isFirst = false;
                holder.setBackgroundRes(R.id.rely_bystages, R.mipmap.pay_moneybg_click);
                holder.setTextColor(R.id.tv_bystages_num, mContext.getResources().getColor(R.color.write));
                holder.setTextColor(R.id.tv_bystages_fen, mContext.getResources().getColor(R.color.write));
                holder.setTextColor(R.id.tv_bystages_qi, mContext.getResources().getColor(R.color.write));
            }
            holder.setVisible(R.id.image_recommend, true);
        } else {
            holder.setVisible(R.id.image_recommend, false);
        }

    }

    public void setSelectPosition(int i) {
        this.defaultSelection = i;
    }

    public void setIsFirst() {
        this.defaultSelection = -1;
        isFirst = true;
    }

    public void setNewData() {

    }
}
